package week5;

public class Ex46 {
    public static void main(String[] args) {
        int n = 10000;
        int[] prime = new int[n];
        int c = 0;
        boolean[] isVisit = new boolean[n+1];
        for (int i = 2; i <= n; ++i){
            if (!isVisit[i])
                prime[++c] = i;
            for (int j = 1; j <= c && i * prime[j] <= n; ++j){
                isVisit[i*prime[j]] = true;
                if (i % prime[j] == 0)
                    break;
            }
        }
        int p;
        boolean flag;
        for (int i = 35; i <= n; i += 2){
            if (isVisit[i]){
                flag = true;
                for (int j = 1; prime[j] < i && j <= c; ++j){
                    p = prime[j];
                    if (((i-p) & 1) == 0 && Math.sqrt((i-p)/2) == (int) Math.sqrt((i-p)/2)){
                        flag = false;
                        break;
                    }
                }
                if (flag){
                    System.out.println(i);
                    break;
                }

            }
        }
    }
}
